package org.lc.service.system.feign;


import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.lc.platform.base.domain.JwtUser;
import org.lc.platform.base.result.Result;
import org.lc.service.system.entity.SysUser;
import org.lc.service.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/feign/user")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Tag(name = "UserFeign|提供微服务调用接口")
@Hidden()
@RefreshScope
public class UserFeign {
    private final SysUserService userService;

    @GetMapping(value = "/query/by/account")
    @Operation(summary = "通过账号查询用户信息")
    public Result<JwtUser> queryByAccount(@RequestParam("account") String account) {
        var user = userService.queryUserByAccount(account);
        return Result.data(user);
    }

    @GetMapping(value = "/online/by/userId")
    @Operation(summary = "通过账号查询用户信息")
    public Result<Boolean> setUserOnlineStats(@RequestParam("userId") String userId, @RequestParam("online") boolean online) {
        var result = userService.lambdaUpdate().eq(SysUser::getId, userId).set(SysUser::isOnline, online).update();
        return Result.data(result);
    }
}
